//
//  EFAMsgControlCVC.m
//  efairy
//  设备聊天界面
//  Created by XiangDongMBP on 2017/8/4.
//  Copyright © 2017年 East. All rights reserved.
//

#import "EFAMsgControlCVC.h"
#import "UIColor+XDHex.h"
#import "GlobalHeader.h"
#import "EFAMsgControlTVC.h"
#import "EFAModel.h"
#import "ApiManager.h"
#import "NSTimer+YYAdd.h"
#import "NSDate+XDTimerFormatter.h"
#import "EFAMsgCfgVC.h"
#import "EFAMsgUpdateVC.h"
#import "AlarmListVC.h"
#import "AlarmDisposeVC.h";

@interface EFAMsgControlCVC ()<EFAMsgControlTVCDelegate>

@property (weak, nonatomic) IBOutlet UIView *promptBgView;
@property (weak, nonatomic) IBOutlet UILabel *promptLabel;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *promptBgViewHeightConstraint;

@property (weak,   nonatomic) IBOutlet UIButton *updateBtn;     //!< 升级
@property (weak,   nonatomic) IBOutlet UIButton *muteBtn;       //!< 消声
@property (weak,   nonatomic) IBOutlet UIButton *resetBtn;      //!< 复位
@property (weak,   nonatomic) IBOutlet UIButton *cfgBtn;        //!< 配置
@property (weak,   nonatomic) IBOutlet NSLayoutConstraint *cfgBtnWidthConstraint;   ///< 配置宽度
@property (weak,   nonatomic) IBOutlet NSLayoutConstraint *updateBtnWidthConstraint;

@property (strong, nonatomic) UIBarButtonItem *filterBarBtnItem;   ///< 过滤按钮
@property (strong, nonatomic) UIBarButtonItem *sureBarBtnItem;     ///< 确定按钮
@property (strong, nonatomic) UIBarButtonItem *cancelBarBtnItem;   ///< 取消按钮
@property (strong, nonatomic) UIBarButtonItem *wholeSelBarBtnItem; ///< 全选(全不选)按钮
@property (assign, nonatomic) BOOL isWholeSel;                     ///< 是否是全选状态
@property (strong, nonatomic) NSArray *typeArray;
@property(strong,nonatomic) UIButton *alarmListBtn;//进入报警列表入口

@property (weak,   nonatomic) EFAMsgControlTVC *msgTVC;

@end

static NSTimeInterval const kMinTimeInterval = 10.0;   //!< 最少间隔10s才能进行第一次操作

@implementation EFAMsgControlCVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self initNavigationBar];
    [self initSubViews];
}

- (BOOL)hidesBottomBarWhenPushed {
    return YES;
}

- (void)initNavigationBar {
    self.navigationItem.title = self.device_name;
    self.navigationItem.rightBarButtonItem = self.filterBarBtnItem;
    self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
}

- (void)initSubViews {
    self.automaticallyAdjustsScrollViewInsets = NO;
    
    NSLog(@"打印id == %ld", (long)self.device_id);
    self.promptBgViewHeightConstraint.constant = 0;
    
    self.muteBtn.layer.borderWidth = 0.5;
    self.muteBtn.layer.borderColor = [UIColor xd_colorWithHex:EFAGlobalColorBorderColor].CGColor;
    [self.muteBtn addTarget:self action:@selector(muteBtnTapped:) forControlEvents:UIControlEventTouchUpInside];
    self.resetBtn.layer.borderWidth = 0.5;
    self.resetBtn.layer.borderColor = [UIColor xd_colorWithHex:EFAGlobalColorBorderColor].CGColor;
    [self.resetBtn addTarget:self action:@selector(resetBtnTapped:) forControlEvents:UIControlEventTouchUpInside];
    self.cfgBtn.layer.borderWidth = 0.5;
    self.cfgBtn.layer.borderColor = [UIColor xd_colorWithHex:EFAGlobalColorBorderColor].CGColor;
    [self.cfgBtn addTarget:self action:@selector(cfgBtnTapped:) forControlEvents:UIControlEventTouchUpInside];
    self.updateBtn.layer.borderWidth = 0.5;
    self.updateBtn.layer.borderColor = [UIColor xd_colorWithHex:EFAGlobalColorBorderColor].CGColor;
    [self.updateBtn addTarget:self action:@selector(updateBtnTapped:) forControlEvents:UIControlEventTouchUpInside];
    
    EFALoginUserRole roleLevel = [EFAModel sharedInstance].loginInfo.user_info.efairyrole_level;
    if (roleLevel == EFALoginUserRoleNormal) {
        self.cfgBtn.hidden = YES;
        self.cfgBtnWidthConstraint.constant = 0;
        self.updateBtn.hidden = YES;
        self.updateBtnWidthConstraint.constant = 0;
    } else if (roleLevel == EFALoginUserRoleSuper) {
        self.cfgBtn.hidden = NO;
        self.cfgBtnWidthConstraint.constant = CGRectGetWidth([UIScreen mainScreen].bounds) / 4.0;
        self.updateBtn.hidden = NO;
        self.updateBtnWidthConstraint.constant = CGRectGetWidth([UIScreen mainScreen].bounds) / 4.0;
    } else {
        self.cfgBtn.hidden = NO;
        self.cfgBtnWidthConstraint.constant = CGRectGetWidth([UIScreen mainScreen].bounds) / 3.0;
        self.updateBtn.hidden = YES;
        self.updateBtnWidthConstraint.constant = 0;
    }
    
    _alarmListBtn = [[UIButton alloc]initWithFrame:CGRectMake(7, SCREEN_HEIGHT-110, 83, 33)];
    _alarmListBtn.layer.backgroundColor =  ColorFromRGB(0x282449).CGColor;
    _alarmListBtn.layer.cornerRadius = 16;
    [_alarmListBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    _alarmListBtn.titleLabel.font = [UIFont systemFontOfSize:15.f];
    [_alarmListBtn setTitle:@"报警列表" forState:UIControlStateNormal];
    [_alarmListBtn addTarget:self  action:@selector(goAlaremListVC) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_alarmListBtn];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
    if ([segue.identifier isEqualToString:@"EFAMsgControlTVC"]) {
        self.msgTVC = segue.destinationViewController;
        NSLog(@"准备segue = %ld", (long)self.device_id);
        self.msgTVC.device_id = self.device_id;
        self.msgTVC.device_name = self.device_name;
        self.msgTVC.isFromDeviceInfo = self.isFromDeviceInfo;
        self.msgTVC.alarm_id = -1;
        self.msgTVC.delegate = self;
    }
}

#pragma mark - EFAMsgControlTVCDelegate
- (void)msgControlTVC:(EFAMsgControlTVC *)vc alarmBtnTapped:(UIButton *)alarmBtn {
    self.isWholeSel = YES;
    [self.wholeSelBarBtnItem setTitle:@"全不选"];
    
//    self.navigationItem.leftBarButtonItem = self.cancelBarBtnItem;
    self.navigationItem.leftBarButtonItems = @[self.cancelBarBtnItem, self.wholeSelBarBtnItem];
    self.navigationItem.rightBarButtonItem = self.sureBarBtnItem;
    [self setControlBtnEnabled:NO];
}
- (void)msgControlTVC:(EFAMsgControlTVC *)vc alarmCount:(NSInteger)alarmCount {
    self.promptLabel.text = [NSString stringWithFormat:@"该设备存在%ld个未处理的严重安全隐患，故新报警信息不会通过短信通知，请及时处理所有报警信息，以免影响正常使用，造成严重后果！", (long)alarmCount];
    self.promptBgViewHeightConstraint.priority = alarmCount ? 250 : 999;
}
#pragma mark - event response
- (void)filterBarBtnTapped:(UIBarButtonItem *)item {
    UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    for (NSDictionary *dic in self.typeArray) {
        [alertVC addAction:[UIAlertAction actionWithTitle:dic[@"alarmTypeName"] style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            [self filterHistoryWithAlarmId:[dic[@"alarmType"] integerValue]];
        }]];
    }
    [alertVC addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];
    [self presentViewController:alertVC animated:YES completion:nil];
}
- (void)cancelBarBtnTapped:(UIBarButtonItem *)item {
//    self.navigationItem.leftBarButtonItem = nil;
    self.navigationItem.leftBarButtonItems = nil;
    self.navigationItem.rightBarButtonItem = self.filterBarBtnItem;
    [self.msgTVC enterEditingMode:NO];
    [self setControlBtnEnabled:YES];
}
- (void)wholeSelBarBtnTapped:(UIBarButtonItem *)item {
    self.isWholeSel = !self.isWholeSel;
    [item setTitle:self.isWholeSel ? @"全不选" : @"全选"];
    
    [self.msgTVC wholeSelOrNot:self.isWholeSel];
}
- (void)sureBarBtnTapped:(UIBarButtonItem *)item {
//    self.navigationItem.leftBarButtonItem = nil;
    self.navigationItem.leftBarButtonItems = nil;
    self.navigationItem.rightBarButtonItem = self.filterBarBtnItem;
    [self.msgTVC completeSelection];
    [self setControlBtnEnabled:YES];
}
- (void)muteBtnTapped:(UIButton *)btn {
    // 开始10s倒计时
    [self setControlBtnEnabled:NO];
    // 检查一下网络连接
    if ([AFNetworkReachabilityManager sharedManager].isReachable) {
        EFAMsgIMItem *msg = [self customMsgIMItemWithOrder:129];
        [self.msgTVC sendMsg:msg];

        // 发送请求
        [self requestControlDeviceWithOrder:129];   //129 - 消音
        [MBProgressHUD showPromptWithAutoHideInView:self.view message:@"10s后才能再次操作"];
        [self startTimer];
    }
}
- (void)resetBtnTapped:(UIButton *)btn {
    // 开始10s倒计时
    [self setControlBtnEnabled:NO];
    // 检查一下网络连接
    if ([AFNetworkReachabilityManager sharedManager].isReachable) {
        EFAMsgIMItem *msg = [self customMsgIMItemWithOrder:128];
        [self.msgTVC sendMsg:msg];
        
        // 发送请求
        [self requestControlDeviceWithOrder:128];   //128 - 复位
        [MBProgressHUD showPromptWithAutoHideInView:self.view message:@"10s后才能再次操作"];
        [self startTimer];
    }
}


//跳转至报警列表页面
-(void)goAlaremListVC{
    AlarmListVC *vc = [[AlarmListVC alloc]init];
    vc.deviceId = self.device_id;
    [self showViewController:vc sender:nil];
}


- (void)cfgBtnTapped:(UIButton *)btn {
    EFAMsgCfgVC *vc = [[EFAMsgCfgVC alloc] init];
    vc.device_id = self.device_id;
    //实现EFAMsgCfgVC block方法 通过block回调来执行保存设备配置
    vc.successHandle = ^(EFADeviceCfgModel *cfgModel) {
        [self doConfigDeviceWithCfgModel:cfgModel];
    };
    [self showViewController:vc sender:nil];
}
- (void)updateBtnTapped:(UIButton *)btn {
    EFAMsgUpdateVC *vc = [[EFAMsgUpdateVC alloc] init];
    vc.device_id = self.device_id;
    vc.successHandle = ^(EFADevVersionItem *versionItem) {
        [self doUpdateDeviceWithVersionItem:versionItem];
    };
    [self showViewController:vc sender:nil];
}
#pragma mark - private methods
- (void)filterHistoryWithAlarmId:(NSInteger)alarm_id {
    [self setControlBtnEnabled:(alarm_id == -1)];
    [self.msgTVC refreshViewWithAlarmId:alarm_id];
}
- (void)doConfigDeviceWithCfgModel:(EFADeviceCfgModel *)cfgModel {
    if (!cfgModel) {
        return;
    }
    // 开始10s倒计时
    [self setControlBtnEnabled:NO];
    // 检查一下网络连接
    if ([AFNetworkReachabilityManager sharedManager].isReachable) {
        EFAMsgIMItem *msg = [self customCfgMsgIMItem];
        [self.msgTVC sendMsg:msg];
        
        // 发送请求
        [self requestConfigDeviceWithCfgModel:cfgModel];   ///< 远程配置
        [MBProgressHUD showPromptWithAutoHideInView:self.view message:@"10s后才能再次操作"];
        [self startTimer];
    }
}
- (void)doUpdateDeviceWithVersionItem:(EFADevVersionItem *)versionItem {
    if (!versionItem) {
        return;
    }
    // 开始10s倒计时
    [self setControlBtnEnabled:NO];
    // 检查一下网络连接
    if ([AFNetworkReachabilityManager sharedManager].isReachable) {
        EFAMsgIMItem *msg = [self customUpdateMsgIMItem];
        [self.msgTVC sendMsg:msg];
        
        // 发送请求
        [self requestUpdateDeviceWithVersionItem:versionItem];
        [MBProgressHUD showPromptWithAutoHideInView:self.view message:@"10s后才能再次操作"];
        [self startTimer];
    }
}
- (EFAMsgIMItem *)customMsgIMItemWithOrder:(NSInteger)order {
    EFAMsgIMItem *msg = [[EFAMsgIMItem alloc] init];
    msg.efairydevicemsg_from_id = [NSString stringWithFormat:@"user_%ld", (long)[EFAModel sharedInstance].loginInfo.user_info.efairyuser_id];
    msg.efairydevicemsg_to_id = [NSString stringWithFormat:@"device_%ld", (long)self.device_id];
    msg.efairydevicemsg_content = (order == 128) ? @"远程复位" : @"远程消声";
    msg.efairydevice_name = self.device_name;
    msg.efairydevicemsg_msgtype = 0;    // 不需要处理
    msg.efairydevicemsg_time = [[NSDate date] xd_yyyy_MM_ddHHmmss];
    msg.efairydevicemsg_ishandle = 0;
    return msg;
}
- (EFAMsgIMItem *)customCfgMsgIMItem {
    EFAMsgIMItem *msg = [[EFAMsgIMItem alloc] init];
    msg.efairydevicemsg_from_id = [NSString stringWithFormat:@"user_%ld", (long)[EFAModel sharedInstance].loginInfo.user_info.efairyuser_id];
    msg.efairydevicemsg_to_id = [NSString stringWithFormat:@"device_%ld", (long)self.device_id];
    msg.efairydevicemsg_content = @"设置设备状态";
    msg.efairydevice_name = self.device_name;
    msg.efairydevicemsg_msgtype = 0;    // 不需要处理
    msg.efairydevicemsg_time = [[NSDate date] xd_yyyy_MM_ddHHmmss];
    msg.efairydevicemsg_ishandle = 0;
    return msg;
}
- (EFAMsgIMItem *)customUpdateMsgIMItem {
    EFAMsgIMItem *msg = [[EFAMsgIMItem alloc] init];
    msg.efairydevicemsg_from_id = [NSString stringWithFormat:@"user_%ld", (long)[EFAModel sharedInstance].loginInfo.user_info.efairyuser_id];
    msg.efairydevicemsg_to_id = [NSString stringWithFormat:@"device_%ld", (long)self.device_id];
    msg.efairydevicemsg_content = @"设备升级";
    msg.efairydevice_name = self.device_name;
    msg.efairydevicemsg_msgtype = 0;    // 不需要处理
    msg.efairydevicemsg_time = [[NSDate date] xd_yyyy_MM_ddHHmmss];
    msg.efairydevicemsg_ishandle = 0;
    return msg;
}
- (void)startTimer {
    __weak typeof(self) weakSelf = self;
    [NSTimer scheduledTimerWithTimeInterval:kMinTimeInterval block:^(NSTimer * _Nonnull timer) {
        [weakSelf setControlBtnEnabled:YES];
    } repeats:NO];
}

- (void)setControlBtnEnabled:(BOOL)enabled {
    self.muteBtn.enabled = enabled;
    self.resetBtn.enabled = enabled;
    self.cfgBtn.enabled = enabled;
    self.updateBtn.enabled = enabled;
}

#pragma mark - network request
- (void)requestControlDeviceWithOrder:(NSInteger)order {
    NSDictionary *pars = @{@"efairyuser_id" : @([EFAModel sharedInstance].loginInfo.user_info.efairyuser_id),
                           @"access_token" : [EFAModel sharedInstance].loginInfo.access_token,
                           @"efairydevice_id" : @(self.device_id),
                           @"control_order" : @(order)};
    NSLog(@"请求控制设备的参数：%@", pars);
    
    [[XDAFNetworking sharedInstance] POST:[ApiManager apiDeviceControl] parameters:pars progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSLog(@"请求控制设备的返回：%@", responseObject);
        // 插入聊天记录(由于这里返回太慢，慢于消息推送，所以这里插入消息就太晚了，暂时不用)
//        EFAMsgIMItem *temp = [EFAMsgIMItem yy_modelWithJSON:responseObject[EFAGlobalJsonKeyResult]];
//        [self.msgTVC sendMsg:temp];
//        // 开始10s倒计时
//        [MBProgressHUD showPromptWithAutoHideInView:self.view message:@"10s后才能再次操作"];
//        [self setControlBtnEnabled:NO];
//        [self startTimer];
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"请求控制设备失败：%@", error);
        NSString *msg = [[ApiErrorCode sharedInstance] errorCodeMsgWithError:error];
        [MBProgressHUD showPromptWithAutoHideInView:self.view message:msg];
    }];
}

- (void)requestConfigDeviceWithCfgModel:(EFADeviceCfgModel *)cfgModel {
    // 需要登录
    if (![EFAModel sharedInstance].isLogin) {
        return;
    }
    
//    MBProgressHUD *hud = [MBProgressHUD xd_showHUDAddedTo:self.view animated:YES];
    NSMutableDictionary *pars = [cfgModel yy_modelToJSONObject];
    [pars setObject:@([EFAModel sharedInstance].loginInfo.user_info.efairyuser_id) forKey:@"efairyuser_id"];
    [pars setObject:[EFAModel sharedInstance].loginInfo.access_token forKey:@"access_token"];
    [pars setObject:@(self.device_id) forKey:@"efairydevice_id"];
    NSLog(@"请求设备配置的参数：%@", pars);
    [[XDAFNetworking sharedInstance] POST:[ApiManager apiDeviceSetting] parameters:pars progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSLog(@"请求设备配置返回：%@", responseObject);
//        [hud hideAnimated:NO];
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"请求设备配置失败：%@", error);
//        [hud hideAnimated:NO];
        NSString *msg = [[ApiErrorCode sharedInstance] errorCodeMsgWithError:error];
        [MBProgressHUD showPromptWithAutoHideInView:self.view message:msg];
    }];
}
- (void)requestUpdateDeviceWithVersionItem:(EFADevVersionItem *)versionItem {
    // 需要登录
    if (![EFAModel sharedInstance].isLogin) {
        return;
    }
    
    //    MBProgressHUD *hud = [MBProgressHUD xd_showHUDAddedTo:self.view animated:YES];
    NSMutableDictionary *pars = [NSMutableDictionary dictionary];
    [pars setObject:@([EFAModel sharedInstance].loginInfo.user_info.efairyuser_id) forKey:@"efairyuser_id"];
    [pars setObject:[EFAModel sharedInstance].loginInfo.access_token forKey:@"access_token"];
    [pars setObject:@[@(self.device_id)] forKey:@"efairydevice_id_list"];
    [pars setObject:versionItem.efairydeviceversion_version forKey:@"dst_version"];
    NSLog(@"请求设备升级的参数：%@", pars);
    [[XDAFNetworking sharedInstance] POST:[ApiManager apiDeviceUpdate] parameters:pars progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSLog(@"请求设备升级返回：%@", responseObject);
        //        [hud hideAnimated:NO];
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"请求设备升级失败：%@", error);
        //        [hud hideAnimated:NO];
        NSString *msg = [[ApiErrorCode sharedInstance] errorCodeMsgWithError:error];
        [MBProgressHUD showPromptWithAutoHideInView:self.view message:msg];
    }];
}
#pragma mark - getters and setters
- (UIBarButtonItem *)filterBarBtnItem {
    if (!_filterBarBtnItem) {
        _filterBarBtnItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"msg_filter"] style:UIBarButtonItemStylePlain target:self action:@selector(filterBarBtnTapped:)];
    }
    return _filterBarBtnItem;
}
- (UIBarButtonItem *)sureBarBtnItem {
    if (!_sureBarBtnItem) {
        _sureBarBtnItem = [[UIBarButtonItem alloc] initWithTitle:@"确定" style:UIBarButtonItemStylePlain target:self action:@selector(sureBarBtnTapped:)];
        NSDictionary * barItemAttributes = @{NSForegroundColorAttributeName: [UIColor xd_colorWithHex:EFAGlobalColorDarkGreen],
                                             NSFontAttributeName: [UIFont systemFontOfSize:15]};
        [_sureBarBtnItem setTitleTextAttributes:barItemAttributes forState:UIControlStateNormal];
        [_sureBarBtnItem setTitleTextAttributes:barItemAttributes forState:UIControlStateSelected];
        NSDictionary * disableBarItemAtt = @{NSForegroundColorAttributeName: [UIColor xd_colorWithHex:EFAGlobalColorDarkGreen alpha:0.5],
                                             NSFontAttributeName: [UIFont systemFontOfSize:15]};
        [_sureBarBtnItem setTitleTextAttributes:disableBarItemAtt forState:UIControlStateDisabled];
    }
    return _sureBarBtnItem;
}
- (UIBarButtonItem *)cancelBarBtnItem {
    if (!_cancelBarBtnItem) {
        _cancelBarBtnItem = [[UIBarButtonItem alloc] initWithTitle:@"取消" style:UIBarButtonItemStylePlain target:self action:@selector(cancelBarBtnTapped:)];
        NSDictionary * barItemAttributes = @{NSForegroundColorAttributeName: [UIColor xd_colorWithHex:EFAGlobalColorDarkGreen],
                                             NSFontAttributeName: [UIFont systemFontOfSize:15]};
        [_cancelBarBtnItem setTitleTextAttributes:barItemAttributes forState:UIControlStateNormal];
        [_cancelBarBtnItem setTitleTextAttributes:barItemAttributes forState:UIControlStateSelected];
        NSDictionary * disableBarItemAtt = @{NSForegroundColorAttributeName: [UIColor xd_colorWithHex:EFAGlobalColorDarkGreen alpha:0.5],
                                             NSFontAttributeName: [UIFont systemFontOfSize:15]};
        [_cancelBarBtnItem setTitleTextAttributes:disableBarItemAtt forState:UIControlStateDisabled];
    }
    return _cancelBarBtnItem;
}
- (UIBarButtonItem *)wholeSelBarBtnItem {
    if (!_wholeSelBarBtnItem) {
        _wholeSelBarBtnItem = [[UIBarButtonItem alloc] initWithTitle:@"全不选" style:UIBarButtonItemStylePlain target:self action:@selector(wholeSelBarBtnTapped:)];
        NSDictionary * barItemAttributes = @{NSForegroundColorAttributeName: [UIColor xd_colorWithHex:EFAGlobalColorDarkGreen],
                                             NSFontAttributeName: [UIFont systemFontOfSize:15]};
        [_wholeSelBarBtnItem setTitleTextAttributes:barItemAttributes forState:UIControlStateNormal];
        [_wholeSelBarBtnItem setTitleTextAttributes:barItemAttributes forState:UIControlStateSelected];
        NSDictionary * disableBarItemAtt = @{NSForegroundColorAttributeName: [UIColor xd_colorWithHex:EFAGlobalColorDarkGreen alpha:0.5],
                                             NSFontAttributeName: [UIFont systemFontOfSize:15]};
        [_wholeSelBarBtnItem setTitleTextAttributes:disableBarItemAtt forState:UIControlStateDisabled];
    }
    return _wholeSelBarBtnItem;
}
- (NSArray *)typeArray {
    if (!_typeArray) {
        _typeArray = @[@{@"alarmType" : @(-1), @"alarmTypeName" : @"全部信息"},
                       @{@"alarmType" : @(1), @"alarmTypeName" : @"火警"},
                       @{@"alarmType" : @(2), @"alarmTypeName" : @"预警"},
                       @{@"alarmType" : @(3), @"alarmTypeName" : @"故障"}];
    }
    return _typeArray;
}

@end
